﻿/**
 * Reboulder - Partial Boulder Dash clone
 * Jesús Sagra, 2014
 * 
 * Sptrite class: basic graphic element to inherit from
 * 
 * Version    Date     Changes
 * -----------------------------------------------------
 *  0.01   07-dic-2014  Attributes, Getters, draw sprites.                
 *  0.02   08-dic-2014  Methods: CollisionsWith , Hide , IsVisible.
 */

class Sprite
{
    protected int x,y;
    protected int height;
    protected int width;
    protected bool visible;
    protected Image image;
    protected int speed;
    protected int row, col;

    public Sprite(int x, int y)
    {
        this.x = x;
        this.y = y;
        this.height = 32;
        this.width = 32;
        this.speed = 0;
        this.visible = true;
        row = (y / 32)-1;
        col = x / 32;
    }

    public Sprite(Sprite s1)
    {
        x = s1.GetX();
        y = s1.GetY();
        height = s1.GetHeight();
        width = s1.GetWidth();
        speed = s1.GetSpeed();
        visible = s1.GetVisible();
        row = s1.GetRow();
        col = s1.GetCol();
    }

    public int GetX()
    {
        return x;
    }

    public bool GetVisible()
    {
        return visible;
    }

    public int GetY()
    {
        return y;
    }

    public void SetRow(int number)
    {
        row = number;
    }

    public int GetRow()
    {
        row = y / 32 -1;
        return row;
    }

    public void SetCol(int number)
    {
        col = number;
    }

    public int GetCol()
    {
        col = x / 32;
        return col;
    }

    public int GetHeight()
    {
        return height;
    }
    
    public int GetWidth()
    {
        return width;
    }

    public int GetSpeed()
    {
        return speed;
    }


    public void Hide()
    {
        visible = false;
    }


    public bool IsVisible()
    {
        return visible;
    }


    public bool CollisionsWith(Sprite otherSprite)
    {
        return (visible && otherSprite.IsVisible() &&
            CollisionsWith(otherSprite.GetX(),
                otherSprite.GetY(),
                otherSprite.GetX() + otherSprite.GetWidth(),
                otherSprite.GetY() + otherSprite.GetHeight()));
    }


    public bool CollisionsWith(int xStart, int yStart, int xEnd, int yEnd)
    {
        if (visible &&
                (x < xEnd) &&
                (x + width > xStart) &&
                (y < yEnd) &&
                (y + height > yStart)
                )
            return true;
        return false;
    }


    public void DrawOnHiddenScreen()
    {
        if (visible)
            SdlHardware.DrawHiddenImage(image, x, y);
    }

    public override string ToString()
    {
        return "sprite";
    }
}